import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 需要左方向动画的路由用this.$router.to('****')
VueRouter.prototype.togo = function (path, par) {
  this.isleft = true
  this.isright = false
  this.push({
    path: path,
    query: par
  })
}
// 跳转指定url路径，但是history栈中不会有记录，点击返回会跳转到上上个页面 (就是直接替换了当前页面)，传参跟push一样
VueRouter.prototype.toReplace = function (path, par) {
  this.isleft = true
  this.isright = false
  this.replace({
    path: path,
    query: par
  })
}
// 需要返回按钮动画的路由用this.$router.goBack()，返回上一个路由
VueRouter.prototype.goBack = function (n) {
  this.isright = true
  this.isleft = false
  this.go(n || -1)
}
const routes = [
	{
		path: '/',
  	name: 'index',
  	component: (resolve) => require(['pages/index'], resolve),
  	redirect: '/home',
  	children: [
			{
  			path: '/home',
  			name: 'home',
  			component: (resolve) => require(['pages/home'], resolve),
  			meta: {
  				title: '首页',
  				type: 'login'
  			}
  		},
  		{
  			path: '/order',
  			name: 'order',
  			component: (resolve) => require(['pages/order'], resolve),
  			meta: {
  				title: '订单',
  				type: 'login'
  			}
  		},
  		{
  			path: '/mine',
  			name: 'mine',
  			component: (resolve) => require(['pages/mine'], resolve),
  			meta: {
  				title: '我的',
  				type: 'login'
  			}
  		}
  	]
  },
  {
  	path: '/login',
  	name: 'login',
  	component: (resolve) => require(['pages/login'], resolve),
  	meta: {
  		title: '登录'
  	}
  },
	{
		path: '/register',
		name: 'register',
		component: (resolve) => require(['pages/register'], resolve),
		meta: {
			title: '注册'
		}
	},
	{
		path: '/address',
		name: 'address',
		component: (resolve) => require(['pages/address'], resolve),
		meta: {
			title: '地址管理'
		}
	},
	{
		path: '/add_address',
		name: 'add_address',
		component: (resolve) => require(['pages/add_address'], resolve),
		meta: {
			title: '新增地址'
		}
	},
	{
		path: '/set_address',
		name: 'set_address',
		component: (resolve) => require(['pages/set_address'], resolve),
		meta: {
			title: '修改地址'
		}
	},
	{
		path: '/comm_detail',
		name: 'comm_detail',
		component: (resolve) => require(['pages/comm_detail'], resolve),
		meta: {
			title: '商品详情'
		}
	},
	{
		path: '/order_detail',
		name: 'order_detail',
		component: (resolve) => require(['pages/order_detail'], resolve),
		meta: {
			title: '订单详情页'
		}
	},
	{
		path: '/hot_comm',
		name: 'hot_comm',
		component: (resolve) => require(['pages/hot_comm'], resolve),
		meta: {
			title: '热门商品'
		}
	},
	{
		path: '/coupon',
		name: 'coupon',
		component: (resolve) => require(['pages/coupon'], resolve),
		meta: {
			title: '我的优惠券'
		}
	},
	{
		path: '/feedback',
		name: 'feedback',
		component: (resolve) => require(['pages/feedback'], resolve),
		meta: {
			title: '意见反馈'
		}
	},
	{
		path: '/search',
		name: 'search',
		component: (resolve) => require(['pages/search'], resolve),
		meta: {
			title: '搜索商品'
		}
	},
	{
		path: '/setting',
		name: 'setting',
		component: (resolve) => require(['pages/setting'], resolve),
		meta: {
			title: '修改信息'
		}
	},
	
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
